﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace library
{
    public class Metadata
    {
        internal byte[] Address;

        internal Dictionary<byte[], byte[]> Data;

        Metadata(byte[] address, Dictionary<byte[], byte[]> data)
        {
            Address = address;

            Data = data;
        }

        //public void AddValue(byte[] value, byte[] field = null)
        //{
        //    field = field ?? 
                
        //    Data.Add()
        //}

        internal static Metadata Load(Stream stream, byte[] address = null)
        {
            byte[] baseAddress = new byte[Parameters.addressSize];

            //stream.Read(baseAddress, 0, 4); //file offset

            stream.Read(baseAddress, 0, Parameters.addressSize);

            Dictionary<byte[], byte[]> metadata = new Dictionary<byte[], byte[]>();

            while (stream.Position < stream.Length)
            {
                byte[] key = Utils.ReadBytes(stream);

                byte[] value = Utils.ReadBytes(stream);

                metadata.Add(key, value);
            }

            return new Metadata(baseAddress, metadata);
        }

        //public static IEnumerable<MetadataKnownField> KnownFields = new [] {

        //    new MetadataKnownField(0)

        //}

        public class MetadataKnownField
        {
            public int Id;

            public ushort Shell32ColumnId;

            public MetadataKnownField(int id, ushort shell32ColumnId = 0)
            {
                Id = id;

                Shell32ColumnId = shell32ColumnId;
            }
        }
    }
}
